home *** CD-ROM | disk | FTP | other *** search
- program TDM61;
- {$APPTYPE CONSOLE}
- uses
- SysUtils, MMSystem;
-
- // resourcestring
-
- function CaptionMaker1(Str: String): String;
- { stack: 256 (arg) + 256 (local) + 256 (result) bytes }
- var
- i: Integer;
- Tmp: String;
- begin
- Tmp := Str; // initial copy
- for i:=1 to Length(Str) do
- if (i = 1) or (Str[i-1] = #32) then
- Tmp[i] := UpCase(Str[i])
- else
- Tmp[i] := Str[i];
- Result := Tmp;
- end;
-
- function CaptionMaker2(Str: String): String;
- { stack: 256 (arg) + 256 (result) bytes }
- var
- i: Integer;
- begin
- for i:=1 to Length(Str) do
- if (i = 1) or (Str[i-1] = #32) then
- Str[i] := UpCase(Str[i]);
- Result := Str
- end;
-
- function CaptionMaker3(const Str: String): String;
- { stack: 256 (result) bytes }
- var
- i: Integer;
- begin
- Result := Str; // initial copy
- for i:=1 to Length(Str) do
- if (i = 1) or (Str[i-1] = #32) then
- Result[i] := UpCase(Str[i])
- end;
-
- procedure CaptionMaker4(var Str: String);
- var
- i: Integer;
- begin
- for i:=1 to Length(Str) do
- if (i = 1) or (Str[i-1] = #32) then
- Str[i] := UpCase(Str[i])
- end;
-
- function CaptionMaker5(var Str: String): PString;
- var
- i: Integer;
- begin
- for i:=1 to Length(Str) do
- if (i = 1) or (Str[i-1] = #32) then
- Str[i] := UpCase(Str[i]);
- Result := @Str
- end;
-
- function ReadFile(const FileName: String): String;
- var
- f: Text;
- Line,Str: String;
- begin
- Str := '';
- Assign(f,FileName);
- Reset(f);
- while not eof(f) do
- begin
- readln(f,Line);
- Str := Str + #13#10 + Line { re-allocate Str }
- end;
- Result := Str
- end;
-
- var
- Str: String;
- Str2: String;
- EndTime: Cardinal;
- Reps: Integer;
- Ch: WideChar;
- var
- X: Array[0..42] of Char;
- Y: PChar;
- begin
- X := 'this is a null-terminated string';
- Y := X; { pointer Y points to X now }
- Y[0] := 'T';
- writeln(X);
-
- Str := 'this is a short string to test';
- Ch := Chr(256 + 32);
- writeln(Ord(Ch));
- Str2 := '';
- //SetLength(Str2,1);
- //if Str2[11] = #32 then writeln('access violation');
-
- Reps := 0;
- EndTime := TimeGetTime + 100;
- repeat
- Inc(Reps);
- Str2 := CaptionMaker1(Str);
- until TimeGetTime > EndTime;
- writeln('1: ',Reps);
- Reps := 0;
- EndTime := TimeGetTime + 100;
- repeat
- Inc(Reps);
- Str2 := CaptionMaker2(Str);
- until TimeGetTime > EndTime;
- writeln('2: ',Reps);
- Reps := 0;
- EndTime := TimeGetTime + 100;
- repeat
- Inc(Reps);
- Str2 := CaptionMaker3(Str);
- until TimeGetTime > EndTime;
- writeln('3: ',Reps);
- Reps := 0;
- EndTime := TimeGetTime + 100;
- repeat
- Inc(Reps);
- CaptionMaker4(Str);
- until TimeGetTime > EndTime;
- writeln('4: ',Reps);
- Reps := 0;
- EndTime := TimeGetTime + 100;
- repeat
- Inc(Reps);
- Str2 := CaptionMaker5(Str)^;
- until TimeGetTime > EndTime;
- writeln('5: ',Reps);
- readln
- end.